<?php

namespace App\Http\Controllers\Game\Config;

use App\Http\Controllers\Controller;
use App\Http\Requests\Game\Config\RtpConfig\RtpConfigRequest;
use App\Http\Resources\Common\DataResource;
use App\Models\Game\Config\System;
use App\Models\Game\Config\System as Config;
use App\Services\Game\Config\RtpConfigService;
use Illuminate\Http\Request;

class RtpConfigController extends Controller
{
    /*配置中心-游戏控制*/

    /**
     * 获取info数据
     * @return DataResource
     */
    public function getData()
    {
        return new DataResource(System::findByType(System::TYPE_INFO));
    }

    /**
     * 修改
     * @param RtpConfigRequest $request
     * @return DataResource
     */
    public function save(RtpConfigRequest $request)
    {

        $data = $request->input('info');

        // 更新或创建
        $config = Config::updateOrCreateByType(Config::TYPE_INFO, $data);

        // 通知游戏端配置修改
        $config->syncGameService();

        return new DataResource($config);
    }
}
